home *** CD-ROM | disk | FTP | other *** search
/ Java for 3D & VRML Worlds / Java for 3d and VRML Worlds.iso / vs / browser / cpn11b1.exe / DATA.Z / tv.java < prev    next >
Text File  |  1996-09-26  |  8KB  |  284 lines

  1. /*-----------------------------------------------------------------------------
  2.  * Copyright(C) 1996 Sony Corporation. All rights reserved.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Sony Corporation;
  6.  * the contents of this file is not to be disclosed to third parties, copied
  7.  * or duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Sony Corporation.
  9.  *
  10.  * File:   tv.java
  11.  * Auther: sugino
  12.  *----------------------------------------------------------------------------*/
  13.  
  14. import vrml.*;
  15. import vrml.field.*;
  16. import vrml.node.*;
  17.  
  18. public class tv extends Script { 
  19.  
  20.     /* propertys */
  21.     /*************************/
  22.     /* channels/volume array */
  23.     /*************************/
  24.     SFFloat channels[] = new SFFloat[3];     /* channelp number shapes */
  25.     SFFloat volumes[]  = new SFFloat[10];    /* volume indicater shapes */
  26.     SFColor powerBtn;                        /* power button */
  27.     SFFloat chs[]      = new SFFloat[3];     /* monitor faces */
  28.     int MaxVolume ;    /* volume max */
  29.     int MaxChannel;    /* channel max */
  30.     int volume    ;    /* sound volume (0-9) */
  31.     int channel   ;    /* channel no(0-2) */
  32.     boolean powerOn ;  /* true the power is on */
  33.     int ignoreTimer ;
  34.     
  35.     SFBool tglTm ;
  36.     
  37.     SFTime bgm1Start ;
  38.     SFTime bgm1Stop  ;
  39.     
  40.     SFTime kachiStart ;
  41.     SFFloat bgmVol    ;
  42.  
  43.     /*************************************************
  44.     * constructor 
  45.     *************************************************/
  46.     public void initialize() {
  47.     
  48.     tglTm = (SFBool)getEventOut("tglTm");
  49.     
  50.     bgm1Start = (SFTime) getEventOut("bgm1Start");
  51.     bgm1Stop = (SFTime) getEventOut("bgm1Stop");
  52.     
  53.     kachiStart = (SFTime) getEventOut("kachiStart");
  54.         bgmVol = (SFFloat) getEventOut("bgmVol");
  55.  
  56.     MaxVolume =10;  /* volume max */
  57.     MaxChannel=3 ;  /* channel max */
  58.     volume = 8 ;    /* sound volume (0-9) */
  59.     channel = 0;    /* channel no(0-2) */
  60.     powerOn = false;/* true the power is on */
  61.  
  62.     /* ---------------------------------------------
  63.      * initialize
  64.      * ------------------------------------------- */
  65.     /* reference to Channnel shapes */
  66.  
  67.     channels[0] = (SFFloat)getEventOut("ch1Shape");
  68.     channels[1] = (SFFloat)getEventOut("ch2Shape");
  69.     channels[2] = (SFFloat)getEventOut("ch3Shape");
  70.  
  71.     chs[0] = (SFFloat)getEventOut("ch1");
  72.     chs[1] = (SFFloat)getEventOut("ch2");
  73.     chs[2] = (SFFloat)getEventOut("ch3");
  74.  
  75.     /* reference to vol indicater shapes */
  76.     volumes[0] = (SFFloat)getEventOut("vol1Shape");
  77.     volumes[1] = (SFFloat)getEventOut("vol2Shape");
  78.     volumes[2] = (SFFloat)getEventOut("vol3Shape");
  79.     volumes[3] = (SFFloat)getEventOut("vol4Shape");
  80.     volumes[4] = (SFFloat)getEventOut("vol5Shape");
  81.     volumes[5] = (SFFloat)getEventOut("vol6Shape");
  82.     volumes[6] = (SFFloat)getEventOut("vol7Shape");
  83.     volumes[7] = (SFFloat)getEventOut("vol8Shape");
  84.     volumes[8] = (SFFloat)getEventOut("vol9Shape");
  85.     volumes[9] = (SFFloat)getEventOut("vol10Shape");
  86.  
  87.     /* reference to Power buttn shapes */
  88.     powerBtn  = (SFColor)getEventOut("powerShape");
  89.  
  90.     bgmVol.setValue((float)volume*0.1f);
  91.     }
  92.     
  93.     public void processEvent(Event e) {
  94.     String name = e.getName();
  95.     ConstField v = (ConstField)e.getValue();
  96.     double t = e.getTimeStamp();
  97.  
  98.     if (name.equals("volDown")){
  99.         volDown ((ConstSFBool)v, t) ;
  100.     }
  101.     else if (name.equals("volUp")) {
  102.         volUp ((ConstSFBool)v, t) ;
  103.     }
  104.     else if (name.equals("chUp")){
  105.         chUp ((ConstSFBool)v, t) ;
  106.     }
  107.     else if (name.equals("chDown")){
  108.         chDown ((ConstSFBool)v, t) ;
  109.     }
  110.     else if(name.equals("tglPower")){
  111.         tglPower ((ConstSFBool)v, t) ;
  112.     }
  113.     else if (name.equals("turnOffInfo")){
  114.         turnOffInfo ((ConstSFTime)v, t) ;
  115.     }
  116.     }
  117.  
  118.     /*************************************************
  119.      * script methods
  120.      *************************************************/
  121.     public void     volDown (ConstSFBool  b, double t){
  122.         if(!powerOn) return ;
  123.     if(b.getValue()){return;}
  124.     /* System.out.println("volDown"); */
  125.     
  126.     volume--;
  127.     setVolume(volume);
  128.     showInfo();
  129.     /* TODO Ä└ì█é╔ë╣é≡âZâbâgé╖éΘ */
  130.     bgmVol.setValue((float)volume*0.1f);
  131.     }
  132.     public void     volUp (ConstSFBool  b, double t){
  133.         if(!powerOn) return ;
  134.     if(b.getValue()){return;}
  135.     /*     System.out.println("volUp"); */
  136.     volume++;
  137.     setVolume(volume);
  138.     showInfo();
  139.     bgmVol.setValue((float)volume*0.1f);
  140.     /* TODO Ä└ì█é╔ë╣é≡âZâbâgé╖éΘ */
  141.     }
  142.     public void     chUp (ConstSFBool  b, double t){
  143.         if(!powerOn) return ;
  144.     if(b.getValue()){return;}
  145.     /* System.out.println("chUp"); */
  146.     channel++;
  147.     setChannel(channel);
  148.     playTv();
  149.     showInfo();
  150.     }
  151.     public void     chDown (ConstSFBool  b, double t){
  152.         if(!powerOn) return ;
  153.     if(b.getValue()){return;}
  154.     /*     System.out.println("chDown"); */
  155.     channel--;
  156.     setChannel(channel);
  157.     playTv();
  158.     showInfo();
  159.     }
  160.     public void     tglPower (ConstSFBool  b, double t){
  161.     
  162.     if(b.getValue()){return;}
  163.     float f[] = new float[3];
  164.     
  165.     f[0]=f[1]=f[2]=0.0f;
  166.     if(powerOn) { 
  167.         /* turn Off power */
  168.         powerOn = false ;
  169.         f[0]=1.0f;
  170.         clearTv();
  171.         clearInfo();
  172.             bgm1Stop.setValue(t);
  173.     }
  174.     else {
  175.         powerOn = true ;
  176.         f[1]=1.0f;
  177.         playTv();
  178.         showInfo();
  179.             bgm1Start.setValue(t);
  180.     }
  181.     powerBtn.setValue(f);
  182.  
  183. /*    System.out.println("tglPower" + ff[0] + " " + 
  184.                ff[1] + " " + ff[2] ); */
  185.  
  186.     kachiStart.setValue(t + 1);
  187.     
  188.     }
  189.     public void turnOffInfo (ConstSFTime time, double t){
  190.  
  191.         if(0<ignoreTimer){
  192.         ignoreTimer--;
  193.             return ;
  194.         }
  195.     tglTm.setValue(false);
  196.         clearInfo();
  197.     clearVolume();
  198.     }
  199.  
  200.     void clearInfo(){
  201.         clearChannel();
  202.     clearVolume();
  203.     }
  204.     /*************************************************
  205.      * showInfo()
  206.      *************************************************/
  207.     void showInfo(){
  208.     setChannel(channel);
  209.     setVolume(volume);
  210.     ignoreTimer = 1;
  211.     tglTm.setValue(true);
  212.     }
  213.  
  214.     /*************************************************
  215.      * Clear TV
  216.      *************************************************/
  217.     void clearTv(){
  218.     for (int i=0;i<MaxChannel;i++){
  219.         chs[i].setValue(1.0f);
  220.     }
  221.     }
  222.     /*************************************************
  223.      * playTv
  224.      *************************************************/
  225.     void playTv(){
  226.     clearTv();
  227.     chs[channel].setValue(0.0f);
  228.     }
  229.     
  230.     /*************************************************
  231.      * Clear Channel shape
  232.      *************************************************/
  233.     void clearChannel(){
  234.     for (int i=0;i<MaxChannel;i++){
  235.         channels[i].setValue(1.0f);
  236.     }
  237.     }
  238.  
  239.     /*************************************************
  240.      * set volume shape
  241.      *************************************************/
  242.     void setChannel(int ch){
  243.     if(ch<0){ch =MaxChannel-1;}
  244.     if(ch>=MaxChannel){ch=0;}
  245.     
  246.     channel = ch ;
  247.     clearChannel();
  248.  
  249.     channels[ch].setValue(0.0f);        
  250.     }
  251.  
  252.     /*************************************************
  253.      * Clear Volume shape
  254.      *************************************************/
  255.     void clearVolume(){
  256.     for(int i=0;i<MaxVolume;i++){
  257.         /* disable volume */
  258.         volumes[i].setValue(1.0f);
  259.     }
  260.     }
  261.  
  262.     /*************************************************
  263.      * set volume shape
  264.      *************************************************/
  265.     void setVolume(int vol){
  266.     if(vol<0){vol =0;}
  267.     if(vol>MaxVolume){vol=MaxVolume;}
  268.     
  269.     volume = vol ;
  270.     clearVolume();
  271.  
  272.     for(int i=0;i<vol;i++){
  273.         volumes[i].setValue(0.0f);        
  274.     }
  275.     }
  276. }
  277.  
  278.  
  279.     
  280.  
  281.  
  282.  
  283.  
  284.